package com.example.ad_project;

import java.util.List;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

import com.nus.iss.ad.model.DepartmentInventoryDetailsModel;

class EditorAdapter extends BaseAdapter {

    Context context;
    List<DepartmentInventoryDetailsModel> data;

    public EditorAdapter(Context context, List<DepartmentInventoryDetailsModel> data){

        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int pos) {
        return data.get(pos);
    }

    @Override
    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.retrival_details_row_layout,null,false);
            holder.qtyExpected = (EditText) convertView.findViewById(R.id.expectedQtyET);
            holder.qtyExpected.addTextChangedListener(new TextWatcher() { 
                public void afterTextChanged(Editable s) {  } 
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {  } 
                public void onTextChanged(CharSequence s, int start, int before, int count) { Log.d("TEST", s+"  In onTextChanged");
                
                } 
            }); 
            holder.deptName = (TextView) convertView.findViewById(R.id.deptName);
            holder.qtyRetrived = (TextView) convertView.findViewById(R.id.deptNameTV);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        holder.deptName.setText(data.get(position).get("deptName"));
        holder.qtyExpected.setText(data.get(position).get("qtyExpected"));
        holder.qtyRetrived.setText(data.get(position).get("qtyRetrived"));

        convertView.setTag(holder);
        return convertView;
    }

    class ViewHolder {
        EditText qtyExpected;
        TextView deptName;
        TextView qtyRetrived;
    }

}
